/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package embeddedpaint;

import embeddedpaint.model.feature.ToolListManager;
import embeddedpaint.model.layers.LayerManager;
import embeddedpaint.user_interface.PanelListOfLayer;
import embeddedpaint.user_interface.PanelWorkspace;
import embeddedpaint.user_interface.ToolBar;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

public class EmbeddedPaint extends JFrame
{
    public  static final String    G_APPLICATION_NAME           = "EmbeddedPane";   
    private static final Dimension M_SCROLL_PANE_PREFERED_SIZED = new Dimension(500, 500);
    
    private JMenuBar               m_menuBar;
    private JScrollPane            m_scrollPane;
    private LayerManager           m_layerManager;
    private PanelWorkspace         m_workspace;

    public EmbeddedPaint ()
    {
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setTitle                (G_APPLICATION_NAME);
        this.setVisible              (true);
        this.setEnabled              (true);

        this.m_layerManager = new LayerManager();
        
        ToolListManager toolListManager = new ToolListManager(this.m_layerManager, this);

        m_workspace = new PanelWorkspace(this.m_layerManager, this);
        
        this.createScroller();

        this.setJMenuBar(m_menuBar);
        
        this.getContentPane().add(this.m_scrollPane,                         BorderLayout.CENTER);
        this.getContentPane().add(new PanelListOfLayer(this.m_layerManager), BorderLayout.EAST);
        this.getContentPane().add(new ToolBar(toolListManager),              BorderLayout.NORTH);

        this.pack();
    }

    private void createScroller ()
    {
        final JPanel panel = new JPanel(new GridLayout());
        
        panel.add(m_workspace);

        this.m_scrollPane = new JScrollPane(panel);
        this.m_scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        this.m_scrollPane.setVerticalScrollBarPolicy  (JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        this.m_scrollPane.setPreferredSize            (M_SCROLL_PANE_PREFERED_SIZED);
        // force repaint when the user scroll
        this.m_scrollPane.setDoubleBuffered           (true);
    }

    public static void main (String[] args)
    {
        EmbeddedPaint embeddedPaint = new EmbeddedPaint();
    }
    
    public JScrollPane getM_scrollPane ()
    {
        return m_scrollPane;
    }

    public PanelWorkspace getM_workspace ()
    {
        return m_workspace;
    }
}